package com.xue.web.servlet;

import com.alibaba.fastjson.JSONObject;
import com.xue.web.controller.LeaveMessageController;
import com.xue.web.controller.LoginController;
import com.xue.web.controller.SendMessageController;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class LeaveMessageServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        System.out.println(this.getClass().getSimpleName()+"|分发请求");
        //解决火狐解析格式不佳
        resp.setContentType("text/html;charset=utf-8");
        String requestURI = req.getRequestURI();
        if (requestURI.endsWith("leaveMessageServlet")){
            LeaveMessageController leaveMessageController =new LeaveMessageController();
            JSONObject jsonObject = leaveMessageController.startGetLeaveMessage();
            String jsonString = jsonObject.toJSONString();
            resp.getWriter().write(jsonString);
        }

        if (requestURI.endsWith("sendMessageServlet")){
            SendMessageController sendMessageController =new SendMessageController();
            JSONObject jsonObject = sendMessageController.startSendLeaveMessage(req,resp);
            String jsonString = jsonObject.toJSONString();
            resp.getWriter().write(jsonString);
        }
    }
}
